package pta;/**
 * @author： li
 * @date： 2022-03-27 20:06
 * @version 1.0
 */
import java.io.*;
public class 考试座位号1 {
    static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    public static void main(String[] args) throws IOException {
        int n =Integer.parseInt(in.readLine());
        String[] zkz = new String[1005];
        int[] pos = new int[1005];
        String[] zzw = new String[1005];
        for(int i=1;i<=n;i++){
            String[] s = in.readLine().split(" ");
            zkz[i] =s[0];
            zzw[i] = s[2];
            pos[Integer.parseInt(s[1])]=i;
        }
        int m = Integer.parseInt(in.readLine());
        String[] c = in.readLine().split(" ");
        for(String i:c){
            int x = Integer.parseInt(i);
            out.write(zkz[pos[x]]+" ");
            out.write(zzw[pos[x]]);
            out.write("\n");
        }
        in.close();
        out.close();
    }
}
